package com.ruoyi.student.service.impl;

import java.util.List;

import com.ruoyi.student.domain.BblClass;
import com.ruoyi.student.dto.changeClassDto;
import com.ruoyi.student.mapper.BblClassMapper;
import com.ruoyi.teaching.domain.BblRepeate;
import com.ruoyi.teaching.mapper.BblRepeateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.student.mapper.StudentMapper;
import com.ruoyi.student.domain.Student;
import com.ruoyi.student.service.IStudentService;

/**
 * 学生Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-05-19
 */
@Service
public class StudentServiceImpl implements IStudentService 
{
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private BblRepeateMapper bblRepeateMapper;
    @Autowired
    private BblClassMapper bblClassMapper;

    /**
     * 查询学生
     * 
     * @param id 学生主键
     * @return 学生
     */
    @Override
    public Student selectStudentById(Long id)
    {
        return studentMapper.selectStudentById(id);
    }

    /**
     * 查询学生列表
     * 
     * @param student 学生
     * @return 学生
     */
    @Override
    public List<Student> selectStudentList(Student student)
    {
        return studentMapper.selectStudentList(student);
    }

    /**
     * 新增学生
     * 
     * @param student 学生
     * @return 结果
     */
    @Override
    public int insertStudent(Student student)
    {
        return studentMapper.insertStudent(student);
    }

    /**
     * 修改学生
     * 
     * @param student 学生
     * @return 结果
     */
    @Override
    public int updateStudent(Student student)
    {
        Long[] ids = student.getIdss();
        if (ids!=null){
            for (Long id : ids) {
                student.setId(id);
                studentMapper.updateStudent(student);
            }
        }
        studentMapper.updateStudent(student);
        return 1;
    }

    /**
     * 批量删除学生
     * 
     * @param ids 需要删除的学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentByIds(Long[] ids)
    {
        return studentMapper.deleteStudentByIds(ids);
    }

    /**
     * 删除学生信息
     * 
     * @param id 学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentById(Long id)
    {
        return studentMapper.deleteStudentById(id);
    }

    /**
     * 学生留级转班
     * @param dto
     * @return
     */
    @Override
    public void changeClass(changeClassDto dto) {
//        如果状态是留级转班
        if(dto.getState()==4){
            BblRepeate bblRepeate = new BblRepeate();
            bblRepeate.setStudent(dto.getName());
//            留级负责老师设置为新的班级的班主任
            BblClass newclass = bblClassMapper.selectBblClassById(dto.getClassId());
//            String teaName = newclass.getClassTeacher().getName();
//            bblRepeate.setDutyTeacher(teaName);
            bblRepeate.setDifficultyNumber("3");
            bblRepeate.setExam("1");
            bblRepeate.setInterview("1");
            bblRepeate.setStudentId(dto.getId());
            bblRepeate.setTeacherId(newclass.getClassTeacherId());
            bblRepeateMapper.insertBblRepeate(bblRepeate);
        }
        studentMapper.changeClass(dto);
    }

    @Override
    public List<Student> findall() {
        return studentMapper.findall();
    }
}
